#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <bitset>
#include <utility>
using namespace std;

#define mm(a, n) memset(a, n, sizeof a)
#define mk(a, b) make_pair(a, b)

const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;

inline void quickread()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

const int N = 1e4 + 10;

int n;
int nums[N];
int v[210][210];

inline void solution()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d", &nums[i]);
    sort(nums, nums + n, greater<int>());

    int r, c;
    for (int i = sqrt(n); i >= 1; i--)
    {
        if (n % i == 0)
        {
            r = n / i;
            c = i;
            break;
        }
    }

    int level = (c + 1) / 2;
    int i = 0;
    for (int L = 0; L < level; L++)
    {
        for (int j = L; j <= c - 1 - L && i < n; j++)
            v[L][j] = nums[i++];
        for (int j = L + 1; j <= r - 1 - L && i < n; j++)
            v[j][c - 1 - L] = nums[i++];
        for (int j = c - 1 - L - 1; j >= L && i < n; j--)
            v[r - 1 - L][j] = nums[i++];
        for (int j = r - 1 - L - 1; j >= L + 1 && i < n; j--)
            v[j][L] = nums[i++];
    }

    for (int i = 0; i < r; i++)
    {
        for (int j = 0; j < c; j++)
        {
            if (j != 0)
                printf(" ");
            printf("%d", v[i][j]);
        }
        printf("\n");
    }
}

int main()
{
    freopen("input.txt", "r", stdin);
    quickread();
    solution();
    return 0;
}